home *** CD-ROM | disk | FTP | other *** search
/ PC/CD Gamer UK 120 / CD Gamer Issue 120 (March 2003) (Disc 2).ISO / mods / Q2_Codered / codeRED1_0.exe / Data1.cab / client.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-12-24  |  16.2 KB  |  593 lines

  1. /*
  2. Copyright (C) 1997-2001 Id Software, Inc.
  3.  
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
  12.  
  13. See the GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18.  
  19. */
  20. // client.h -- primary header for client
  21.  
  22. //define    PARANOID            // speed sapping error checking
  23.  
  24. #include <math.h>
  25. #include <string.h>
  26. #include <stdarg.h>
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29.  
  30. #include "ref.h"
  31.  
  32. #include "vid.h"
  33. #include "screen.h"
  34. #include "sound.h"
  35. #include "input.h"
  36. #include "keys.h"
  37. #include "console.h"
  38. #include "cdaudio.h"
  39.  
  40. //=============================================================================
  41.  
  42. typedef struct
  43. {
  44.     qboolean        valid;            // cleared if delta parsing was invalid
  45.     int                serverframe;
  46.     int                servertime;        // server time the message is valid for (in msec)
  47.     int                deltaframe;
  48.     byte            areabits[MAX_MAP_AREAS/8];        // portalarea visibility bits
  49.     player_state_t    playerstate;
  50.     int                num_entities;
  51.     int                parse_entities;    // non-masked index into cl_parse_entities array
  52. } frame_t;
  53.  
  54. typedef struct
  55. {
  56.     entity_state_t    baseline;        // delta from this if not from a previous frame
  57.     entity_state_t    current;
  58.     entity_state_t    prev;            // will always be valid, but might just be a copy of current
  59.  
  60.     int            serverframe;        // if not current, this ent isn't in the frame
  61.  
  62.     int            trailcount;            // for diminishing grenade trails
  63.     vec3_t        lerp_origin;        // for trails (variable hz)
  64.  
  65.     int            fly_stoptime;
  66. } centity_t;
  67.  
  68. #define MAX_CLIENTWEAPONMODELS        20        // PGM -- upped from 16 to fit the chainfist vwep
  69.  
  70. typedef struct
  71. {
  72.     char    name[MAX_QPATH];
  73.     char    cinfo[MAX_QPATH];
  74.     struct image_s    *skin;
  75.     struct image_s    *icon;
  76.     char    iconname[MAX_QPATH];
  77.     struct model_s    *model;
  78.     struct model_s    *weaponmodel[MAX_CLIENTWEAPONMODELS];
  79. } clientinfo_t;
  80.  
  81. extern char cl_weaponmodels[MAX_CLIENTWEAPONMODELS][MAX_QPATH];
  82. extern int num_cl_weaponmodels;
  83.  
  84. #define    CMD_BACKUP        64    // allow a lot of command backups for very fast systems
  85.  
  86. //
  87. // the client_state_t structure is wiped completely at every
  88. // server map change
  89. //
  90. typedef struct
  91. {
  92.     int            timeoutcount;
  93.  
  94.     int            timedemo_frames;
  95.     int            timedemo_start;
  96.  
  97.     qboolean    refresh_prepped;    // false if on new level or new ref dll
  98.     qboolean    sound_prepped;        // ambient sounds can start
  99.     qboolean    force_refdef;        // vid has changed, so we can't use a paused refdef
  100.  
  101.     int            parse_entities;        // index (not anded off) into cl_parse_entities[]
  102.  
  103.     usercmd_t    cmd;
  104.     usercmd_t    cmds[CMD_BACKUP];    // each mesage will send several old cmds
  105.     int            cmd_time[CMD_BACKUP];    // time sent, for calculating pings
  106.     short        predicted_origins[CMD_BACKUP][3];    // for debug comparing against server
  107.  
  108.     float        predicted_step;                // for stair up smoothing
  109.     unsigned    predicted_step_time;
  110.  
  111.     vec3_t        predicted_origin;    // generated by CL_PredictMovement
  112.     vec3_t        predicted_angles;
  113.     vec3_t        prediction_error;
  114.  
  115.     frame_t        frame;                // received from server
  116.     int            surpressCount;        // number of messages rate supressed
  117.     frame_t        frames[UPDATE_BACKUP];
  118.  
  119.     // the client maintains its own idea of view angles, which are
  120.     // sent to the server each frame.  It is cleared to 0 upon entering each level.
  121.     // the server sends a delta each frame which is added to the locally
  122.     // tracked view angles to account for standing on rotating objects,
  123.     // and teleport direction changes
  124.     vec3_t        viewangles;
  125.  
  126.     int            time;            // this is the time value that the client
  127.                                 // is rendering at.  always <= cls.realtime
  128.     float        lerpfrac;        // between oldframe and frame
  129.  
  130.     refdef_t    refdef;
  131.  
  132.     vec3_t        v_forward, v_right, v_up;    // set when refdef.angles is set
  133.  
  134.     //
  135.     // transient data from server
  136.     //
  137.     char        layout[1024];        // general 2D overlay
  138.     int            inventory[MAX_ITEMS];
  139.  
  140.     //
  141.     // non-gameserver infornamtion
  142.     // FIXME: move this cinematic stuff into the cin_t structure
  143.     FILE        *cinematic_file;
  144.     int            cinematictime;        // cls.realtime for first cinematic frame
  145.     int            cinematicframe;
  146.     char        cinematicpalette[768];
  147.     qboolean    cinematicpalette_active;
  148.  
  149.     //
  150.     // server state information
  151.     //
  152.     qboolean    attractloop;        // running the attract loop, any key will menu
  153.     int            servercount;    // server identification for prespawns
  154.     char        gamedir[MAX_QPATH];
  155.     int            playernum;
  156.  
  157.     char        configstrings[MAX_CONFIGSTRINGS][MAX_QPATH];
  158.  
  159.     //
  160.     // locally derived information from server state
  161.     //
  162.     struct model_s    *model_draw[MAX_MODELS];
  163.     struct cmodel_s    *model_clip[MAX_MODELS];
  164.  
  165.     struct sfx_s    *sound_precache[MAX_SOUNDS];
  166.     struct image_s    *image_precache[MAX_IMAGES];
  167.  
  168.     clientinfo_t    clientinfo[MAX_CLIENTS];
  169.     clientinfo_t    baseclientinfo;
  170. } client_state_t;
  171.  
  172. extern    client_state_t    cl;
  173.  
  174. /*
  175. ==================================================================
  176.  
  177. the client_static_t structure is persistant through an arbitrary number
  178. of server connections
  179.  
  180. ==================================================================
  181. */
  182.  
  183. typedef enum {
  184.     ca_uninitialized,
  185.     ca_disconnected,     // not talking to a server
  186.     ca_connecting,        // sending request packets to the server
  187.     ca_connected,        // netchan_t established, waiting for svc_serverdata
  188.     ca_active            // game views should be displayed
  189. } connstate_t;
  190.  
  191. typedef enum {
  192.     dl_none,
  193.     dl_model,
  194.     dl_sound,
  195.     dl_skin,
  196.     dl_single
  197. } dltype_t;        // download type
  198.  
  199. typedef enum {key_game, key_console, key_message, key_menu} keydest_t;
  200.  
  201. typedef struct
  202. {
  203.     connstate_t    state;
  204.     keydest_t    key_dest;
  205.  
  206.     int            framecount;
  207.     int            realtime;            // always increasing, no clamping, etc
  208.     float        frametime;            // seconds since last frame
  209.  
  210. // screen rendering information
  211.     float        disable_screen;        // showing loading plaque between levels
  212.                                     // or changing rendering dlls
  213.                                     // if time gets > 30 seconds ahead, break it
  214.     int            disable_servercount;    // when we receive a frame and cl.servercount
  215.                                     // > cls.disable_servercount, clear disable_screen
  216.  
  217. // connection information
  218.     char        servername[MAX_OSPATH];    // name of server from original connect
  219.     float        connect_time;        // for connection retransmits
  220.  
  221.     int            quakePort;            // a 16 bit value that allows quake servers
  222.                                     // to work around address translating routers
  223.     netchan_t    netchan;
  224.     int            serverProtocol;        // in case we are doing some kind of version hack
  225.  
  226.     int            challenge;            // from the server to use for connecting
  227.  
  228.     FILE        *download;            // file transfer from server
  229.     char        downloadtempname[MAX_OSPATH];
  230.     char        downloadname[MAX_OSPATH];
  231.     int            downloadnumber;
  232.     dltype_t    downloadtype;
  233.     int            downloadpercent;
  234.  
  235. // demo recording info must be here, so it isn't cleared on level change
  236.     qboolean    demorecording;
  237.     qboolean    demowaiting;    // don't record until a non-delta message is received
  238.     FILE        *demofile;
  239. } client_static_t;
  240.  
  241. extern client_static_t    cls;
  242.  
  243. //=============================================================================
  244.  
  245. //
  246. // cvars
  247. //
  248. extern    cvar_t    *cl_stereo_separation;
  249. extern    cvar_t    *cl_stereo;
  250.  
  251. extern    cvar_t    *cl_gun;
  252. extern    cvar_t    *cl_add_blend;
  253. extern    cvar_t    *cl_add_lights;
  254. extern    cvar_t    *cl_add_particles;
  255. extern    cvar_t    *cl_add_entities;
  256. extern    cvar_t    *cl_predict;
  257. extern    cvar_t    *cl_footsteps;
  258. extern    cvar_t    *cl_noskins;
  259. extern    cvar_t    *cl_autoskins;
  260.  
  261. extern    cvar_t    *cl_upspeed;
  262. extern    cvar_t    *cl_forwardspeed;
  263. extern    cvar_t    *cl_sidespeed;
  264.  
  265. extern    cvar_t    *cl_yawspeed;
  266. extern    cvar_t    *cl_pitchspeed;
  267.  
  268. extern    cvar_t    *cl_run;
  269.  
  270. extern    cvar_t    *cl_anglespeedkey;
  271.  
  272. extern    cvar_t    *cl_shownet;
  273. extern    cvar_t    *cl_showmiss;
  274. extern    cvar_t    *cl_showclamp;
  275.  
  276. extern    cvar_t    *lookspring;
  277. extern    cvar_t    *lookstrafe;
  278. extern    cvar_t    *sensitivity;
  279.  
  280. extern    cvar_t    *m_pitch;
  281. extern    cvar_t    *m_yaw;
  282. extern    cvar_t    *m_forward;
  283. extern    cvar_t    *m_side;
  284.  
  285. extern    cvar_t    *freelook;
  286.  
  287. extern    cvar_t    *cl_lightlevel;    // FIXME HACK
  288.  
  289. extern    cvar_t    *cl_paused;
  290. extern    cvar_t    *cl_timedemo;
  291.  
  292. extern    cvar_t    *cl_vwep;
  293.  
  294. typedef struct
  295. {
  296.     int        key;                // so entities can reuse same entry
  297.     vec3_t    color;
  298.     vec3_t    origin;
  299.     float    radius;
  300.     float    die;                // stop lighting after this time
  301.     float    decay;                // drop this each second
  302.     float    minlight;            // don't add when contributing less
  303. } cdlight_t;
  304.  
  305. extern    centity_t    cl_entities[MAX_EDICTS];
  306. extern    cdlight_t    cl_dlights[MAX_DLIGHTS];
  307.  
  308. // the cl_parse_entities must be large enough to hold UPDATE_BACKUP frames of
  309. // entities, so that when a delta compressed message arives from the server
  310. // it can be un-deltad from the original 
  311. #define    MAX_PARSE_ENTITIES    1024
  312. extern    entity_state_t    cl_parse_entities[MAX_PARSE_ENTITIES];
  313.  
  314. //=============================================================================
  315.  
  316. extern    netadr_t    net_from;
  317. extern    sizebuf_t    net_message;
  318.  
  319. void DrawString (int x, int y, char *s);
  320. void DrawAltString (int x, int y, char *s);    // toggle high bit
  321. qboolean    CL_CheckOrDownloadFile (char *filename);
  322.  
  323. void CL_AddNetgraph (void);
  324.  
  325. //ROGUE
  326. typedef struct cl_sustain
  327. {
  328.     int            id;
  329.     int            type;
  330.     int            endtime;
  331.     int            nextthink;
  332.     int            thinkinterval;
  333.     vec3_t        org;
  334.     vec3_t        dir;
  335.     int            color;
  336.     int            count;
  337.     int            magnitude;
  338.     void        (*think)(struct cl_sustain *self);
  339. } cl_sustain_t;
  340.  
  341. #define MAX_SUSTAINS        32
  342. void CL_ParticleSteamEffect2(cl_sustain_t *self);
  343. void CL_ParticleFireEffect2(cl_sustain_t *self);
  344. void CL_ParticleSmokeEffect2(cl_sustain_t *self);
  345. void CL_TeleporterParticles (entity_state_t *ent);
  346. void CL_ParticleEffect (vec3_t org, vec3_t dir, int color, int count);
  347. void CL_ParticleEffect2 (vec3_t org, vec3_t dir, int color, int count);
  348.  
  349. // RAFAEL
  350. void CL_ParticleEffect3 (vec3_t org, vec3_t dir, int color, int count);
  351.  
  352.  
  353. //=================================================
  354.  
  355. // ========
  356. // PGM
  357. typedef struct particle_s
  358. {
  359.     struct particle_s    *next;
  360.  
  361.     float        time;
  362.  
  363.     vec3_t        org;
  364.     vec3_t        vel;
  365.     vec3_t        accel;
  366.     float        color;
  367.     float        colorvel;
  368.     float        alpha;
  369.     float        alphavel;
  370.     int            type;        // 0 standard, 1 smoke, etc etc...
  371. } cparticle_t;
  372.  
  373.  
  374. #define    PARTICLE_GRAVITY    40
  375. #define BLASTER_PARTICLE_COLOR        0xe0
  376. // PMM
  377. #define INSTANT_PARTICLE    -10000.0
  378. // PGM
  379. // ========
  380.  
  381. void CL_ClearEffects (void);
  382. void CL_ClearTEnts (void);
  383. void CL_BlasterTrail (vec3_t start, vec3_t end);
  384. void CL_QuadTrail (vec3_t start, vec3_t end);
  385. void CL_RailTrail (vec3_t start, vec3_t end);
  386. void CL_LaserTrail (vec3_t start, vec3_t end);
  387. void CL_BlasterBeamTrail (vec3_t start, vec3_t end);
  388. void CL_LaserBlast (vec3_t start, vec3_t end);
  389. void CL_LaserBlast2 (vec3_t start, vec3_t end);
  390. void CL_HeatBlast (vec3_t start, vec3_t end);
  391. void CL_BubbleTrail (vec3_t start, vec3_t end);
  392. void CL_FlagTrail (vec3_t start, vec3_t end, float color);
  393. void CL_NewLightning (vec3_t start, vec3_t end);
  394.  
  395. // RAFAEL
  396. void CL_IonripperTrail (vec3_t start, vec3_t end);
  397.  
  398. // ========
  399. // PGM
  400. void CL_BlasterParticles2 (vec3_t org, vec3_t dir, unsigned int color);
  401. void CL_BlasterTrail2 (vec3_t start, vec3_t end);
  402. void CL_DebugTrail (vec3_t start, vec3_t end);
  403. void CL_SmokeTrail (vec3_t start, vec3_t end, int colorStart, int colorRun, int spacing);
  404. void CL_Flashlight (int ent, vec3_t pos);
  405. void CL_ForceWall (vec3_t start, vec3_t end, int color);
  406. void CL_FlameEffects (centity_t *ent, vec3_t origin);
  407. void CL_GenericParticleEffect (vec3_t org, vec3_t dir, int color, int count, int numcolors, int dirspread, float alphavel);
  408. void CL_BubbleTrail2 (vec3_t start, vec3_t end, int dist);
  409. void CL_Heatbeam (vec3_t start, vec3_t end);
  410. void CL_ParticleSteamEffect (vec3_t org, vec3_t dir, int color, int count, int magnitude);
  411. void CL_TrackerTrail (vec3_t start, vec3_t end, int particleColor);
  412. void CL_Tracker_Explode(vec3_t origin);
  413. void CL_TagTrail (vec3_t start, vec3_t end, float color);
  414. void CL_ColorFlash (vec3_t pos, int ent, int intensity, float r, float g, float b);
  415. void CL_Tracker_Shell(vec3_t origin);
  416. void CL_MonsterPlasma_Shell(vec3_t origin);
  417. void CL_ColorExplosionParticles (vec3_t org, int color, int run);
  418. void CL_ParticleSmokeEffect (vec3_t org, vec3_t dir, int color, int count, int magnitude);
  419. void CL_Widowbeamout (cl_sustain_t *self);
  420. void CL_Nukeblast (cl_sustain_t *self);
  421. void CL_WidowSplash (vec3_t org);
  422. // PGM
  423. // ========
  424.  
  425. int CL_ParseEntityBits (unsigned *bits);
  426. void CL_ParseDelta (entity_state_t *from, entity_state_t *to, int number, int bits);
  427. void CL_ParseFrame (void);
  428.  
  429. void CL_ParseTEnt (void);
  430. void CL_ParseConfigString (void);
  431. void CL_ParseMuzzleFlash (void);
  432. void CL_ParseMuzzleFlash2 (void);
  433. void SmokeAndFlash(vec3_t origin);
  434.  
  435. void CL_SetLightstyle (int i);
  436.  
  437. void CL_RunParticles (void);
  438. void CL_RunDLights (void);
  439. void CL_RunLightStyles (void);
  440.  
  441. void CL_AddEntities (void);
  442. void CL_AddDLights (void);
  443. void CL_AddTEnts (void);
  444. void CL_AddLightStyles (void);
  445.  
  446. //=================================================
  447.  
  448. void CL_PrepRefresh (void);
  449. void CL_RegisterSounds (void);
  450.  
  451. void CL_Quit_f (void);
  452.  
  453. void IN_Accumulate (void);
  454.  
  455. void CL_ParseLayout (void);
  456.  
  457.  
  458. //
  459. // cl_main
  460. //
  461. void CL_Init (void);
  462.  
  463. void CL_FixUpGender(void);
  464. void CL_Disconnect (void);
  465. void CL_Disconnect_f (void);
  466. void CL_GetChallengePacket (void);
  467. void CL_PingServers_f (void);
  468. void CL_Snd_Restart_f (void);
  469. void CL_RequestNextDownload (void);
  470.  
  471. //
  472. // cl_input
  473. //
  474. typedef struct
  475. {
  476.     int            down[2];        // key nums holding it down
  477.     unsigned    downtime;        // msec timestamp
  478.     unsigned    msec;            // msec down this frame
  479.     int            state;
  480. } kbutton_t;
  481.  
  482. extern    kbutton_t    in_mlook, in_klook;
  483. extern     kbutton_t     in_strafe;
  484. extern     kbutton_t     in_speed;
  485.  
  486. void CL_InitInput (void);
  487. void CL_SendCmd (void);
  488. void CL_SendMove (usercmd_t *cmd);
  489.  
  490. void CL_ClearState (void);
  491.  
  492. void CL_ReadPackets (void);
  493.  
  494. int  CL_ReadFromServer (void);
  495. void CL_WriteToServer (usercmd_t *cmd);
  496. void CL_BaseMove (usercmd_t *cmd);
  497.  
  498. void IN_CenterView (void);
  499.  
  500. float CL_KeyState (kbutton_t *key);
  501. char *Key_KeynumToString (int keynum);
  502.  
  503. //
  504. // cl_demo.c
  505. //
  506. void CL_WriteDemoMessage (void);
  507. void CL_Stop_f (void);
  508. void CL_Record_f (void);
  509.  
  510. //
  511. // cl_parse.c
  512. //
  513. extern    char *svc_strings[256];
  514.  
  515. void CL_ParseServerMessage (void);
  516. void CL_LoadClientinfo (clientinfo_t *ci, char *s);
  517. void SHOWNET(char *s);
  518. void CL_ParseClientinfo (int player);
  519. void CL_Download_f (void);
  520.  
  521. //
  522. // cl_view.c
  523. //
  524. extern    int            gun_frame;
  525. extern    struct model_s    *gun_model;
  526.  
  527. void V_Init (void);
  528. void V_RenderView( float stereo_separation );
  529. void V_AddEntity (entity_t *ent);
  530. void V_AddParticle (vec3_t org, int color, int type, float alpha);
  531. void V_AddLight (vec3_t org, float intensity, float r, float g, float b);
  532. void V_AddLightStyle (int style, float r, float g, float b);
  533. void V_AddStain (vec3_t org, float intensity, float r, float g, float b, float a);
  534.  
  535. //
  536. // cl_tent.c
  537. //
  538. void CL_RegisterTEntSounds (void);
  539. void CL_RegisterTEntModels (void);
  540. void CL_SmokeAndFlash(vec3_t origin);
  541.  
  542.  
  543. //
  544. // cl_pred.c
  545. //
  546. void CL_InitPrediction (void);
  547. void CL_PredictMove (void);
  548. void CL_CheckPredictionError (void);
  549.  
  550. //
  551. // cl_fx.c
  552. //
  553. cdlight_t *CL_AllocDlight (int key);
  554. void CL_BigTeleportParticles (vec3_t org);
  555. void CL_RocketTrail (vec3_t start, vec3_t end, centity_t *old);
  556. void CL_ShipExhaust (vec3_t start, vec3_t end, centity_t *old);
  557. void CL_DiminishingTrail (vec3_t start, vec3_t end, centity_t *old, int flags);
  558. void CL_FlyEffect (centity_t *ent, vec3_t origin);
  559. void CL_BfgParticles (entity_t *ent);
  560. void CL_AddParticles (void);
  561. void CL_EntityEvent (entity_state_t *ent);
  562. // RAFAEL
  563. void CL_TrapParticles (entity_t *ent);
  564.  
  565. //
  566. // menus
  567. //
  568. void M_Init (void);
  569. void M_Keydown (int key);
  570. void M_Draw (void);
  571. void M_Menu_Main_f (void);
  572. void M_ForceMenuOff (void);
  573. void M_AddToServerList (netadr_t adr, char *info);
  574.  
  575. //
  576. // cl_inv.c
  577. //
  578. void CL_ParseInventory (void);
  579. void CL_KeyInventory (int key);
  580. void CL_DrawInventory (void);
  581.  
  582. //
  583. // cl_pred.c
  584. //
  585. void CL_PredictMovement (void);
  586.  
  587. #if id386
  588. void x86_TimerStart( void );
  589. void x86_TimerStop( void );
  590. void x86_TimerInit( unsigned long smallest, unsigned longest );
  591. unsigned long *x86_TimerGetHistogram( void );
  592. #endif
  593.